<template>
	<view class="find">
		<!-- tab切换 -->
		<view class="tab">
			<radio-group @change="tabChange">
				<label v-for="item in tabList" :key="item.id">
					<radio :value="item.id" :checked="item.checked" /><text
						:class="['text',item.checked==true ? 'tabActive':'']">{{item.name}}</text>
				</label>
			</radio-group>
		</view>
		<!-- 精选文章 -->
		<view class="article" :style="{display:display1}">
			<view class="article_item" v-for="item in articleList" :key="item.id" @tap="toArticleDetail(item.id)">
				<view class="article_tit">
					<view class="tit">
						{{item.title}}
					</view>
					<view class="author">
						{{item.author}}
					</view>
				</view>
				<image class="article_img" :src="item.coverImg"></image>
				<view class="article_info">
					<view class="info_left">
						<image src="../../static/icons/view.png" mode=""></image>
						<text>{{item.viewCount}}</text>
					</view>

					<view class="info_right">
						<uni-icons type="star" size="30"></uni-icons>
					</view>
				</view>
			</view>
		</view>

		<!-- 品牌列表 -->
		<view class="brand" :style="{display:display2}">
			<view class="brand_item" v-for="item in brandList" :key="item.id">
				<image class="brand_img" :src="item.bigPic" mode=""></image>
				<view class="brand_info">
					<view class="tit">
						{{item.name}}
					</view>
					<view class="descr">
						{{item.brandStory}}
					</view>
				</view>
			</view>
		</view>


	</view>
</template>

<script>
	//api
	import {
		findArticleByPage,
		findBrandsByPage
	} from "@/api/find/index.js"
	export default {
		data() {
			return {
				tabList: [{
						id: '1',
						checked: true,
						name: '精选文章'
					},
					{
						id: '2',
						checked: false,
						name: '品牌列表'
					},
				],
				display1: 'block',
				display2: 'none',
				articleList: [],
				brandList: [],
			}
		},
		onLoad() {
			this.getArticle();
			this.getBrand();
		},
		methods: {
			// tab切换
			tabChange(event) {
				console.log(event.detail.value);
				if (event.detail.value == '1') {
					this.display1 = 'block';
					this.display2 = 'none';
				} else if (event.detail.value == '2') {
					this.display1 = 'none';
					this.display2 = 'block';
				}
				this.tabList.forEach((el) => {
					el.checked = false
					if (el.id == event.detail.value) {
						el.checked = true
					}
				})
			},

			//获取精选文章
			getArticle() {
				findArticleByPage(1, 10).then(res => {
					console.log(res);
					let {
						data
					} = res.data;
					this.articleList = data.rows;
				})
			},

			//获取品牌列表
			getBrand() {
				findBrandsByPage(1, 10).then(res => {
					console.log(res);
					let {
						data
					} = res.data;
					this.brandList = data.rows;
				})
			},
			
			//跳转到文章详情
			toArticleDetail(id){
				uni.navigateTo({
					url:'/pages/articleDetail/articleDetail?id=' + id
				})
			}
		}
	}
</script>

<style lang="scss">
	.find {
		.tab {
			width: 100%;
			height: 88rpx;
			display: flex;
			justify-content: space-around;
			align-items: center;
			color: #fff;
			font-size: 16px;
			background-color: rgb(53, 78, 68);
			margin-bottom: 20rpx;

			radio-group {
				.uni-label-pointer {
					uni-radio {
						display: none;
					}

					.text {
						line-height: 44px;
						box-sizing: border-box;
						padding: 5px 0;
						margin: 0 5px;
					}
				}

			}

			.tabActive {
				border-bottom: 1px solid #fff;
			}


		}

		.article {
			margin: 0 38rpx;

			.article_item {
				width: 674rpx;
				color: #fff;
				border-radius: 24rpx;
				background-color: #fff;
				margin-bottom: 28rpx;
				position: relative;

				.article_tit {
					width: 80%;
					height: 100rpx;
					position: absolute;
					left: 20rpx;
					top: 240rpx;
					z-index: 999;

					.tit {
						font-size: 48rpx;
						line-height: 68rpx;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
					}

					.author {
						font-size: 30rpx;
						line-height: 42rpx;
					}
				}

				.article_img {
					width: 100%;
					height: 382rpx;
					background-color: #8f8f94;
					border-top-left-radius: 24rpx;
					border-top-right-radius: 24rpx;
				}

				.article_info {
					height: 100rpx;
					padding: 0 60rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.info_left {
						display: flex;
						align-items: center;

						image {
							width: 60rpx;
							height: 40rpx;
							margin-right: 10rpx;
						}

						text {
							font-size: 26rpx;
							color: #999;
						}
					}
				}
			}

		}

		.brand {
			margin: 0 30rpx;

			.brand_item {
				width: 690rpx;
				background: #fff;
				border-radius: 24rpx;
				overflow: hidden;
				margin-bottom: 30rpx;

				.brand_img {
					width: 100%;
					height: 480rpx;
					border-top-left-radius: 24rpx;
					border-top-right-radius: 24rpx;

				}

				.brand_info {
					margin: 30rpx;

					.tit {
						font-size: 32rpx;
						line-height: 44rpx;
						color: #3e3e3e;
					}

					.descr {
						font-size: 24rpx;
						color: #b1b1b1;
						line-height: 30rpx;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}
				}
			}
		}
	}
</style>
